public class ListNode {
    public int val;
    public ListNode next;
    public ListNode(int val,ListNode next){
        this.val=val;
        this.next=next;
    }
    public ListNode(){
        ;
    }
    public ListNode reserve(ListNode o1){//反转链表
        if(o1==null||o1.next==null){
            return o1;
        }
        ListNode n1=o1;
        ListNode next=o1.next;
        while (next!=null){
            o1.next=next.next;
            next.next=n1;
            n1=next;
            next=o1.next;
        }
        return n1;
    }

    @Override
    public String toString() {
        return "ListNode{" +
                "val=" + val +
                ", next=" + next +
                '}';
    }
}
